package apple.encryptedNode.view;

import it.telecomitalia.jchat.R;

import java.util.ArrayList;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ListView;

import apple.encryptedNode.adapter.NodeAdapter;
import apple.encryptedNode.dao.OperationDAO;
import apple.encryptedNode.vo.Node;
/***
 * 自定义秘密箱listView
 * ***/
public class NodeListView extends ListView {
	private final String TAG = NodeListView.class.getSimpleName();

	private ArrayList<Node> list = new ArrayList<Node>();
	private NodeAdapter adapter;
	private OperationDAO dao;

	public NodeListView(Context context, AttributeSet attrs) {
		super(context, attrs);

		Log.d(TAG, "NodeListView");

		dao = new OperationDAO(getContext());
		adapter = new NodeAdapter(context, R.layout.note_list_component, list);
		setAdapter(adapter);

		refresh();
	}
	
	public ArrayList<Node> getList() {
		return list;
	}

	/***
	 * 查询所有记录
	 * **/
	public void refresh() {
		Log.i(TAG, "refresh");

		list.clear();
		ArrayList<Node> data = dao.getList();
		for (Node bean : data) {
			list.add(bean);
		}
		adapter.notifyDataSetChanged();
	}
}
